package com.yuyou.fn.report.service.impl;

import com.github.wens.framework.service.impl.SuperServiceImpl;
import com.github.wens.mybatisplus.examples.Example;
import com.github.wens.mybatisplus.plugins.Page;
import com.yuyou.fn.common.util.CriteriaUtils;
import com.yuyou.fn.common.util.Utils;
import com.yuyou.fn.report.entity.CostOfGradeSubject;
import com.yuyou.fn.report.mapper.CostOfGradeSubjectMapper;
import com.yuyou.fn.report.service.ICostOfGradeSubjectService;
import com.yuyou.fn.report.vo.GradeSubjectCostQueryVo;
import com.yuyou.fn.report.vo.GradeSubjectCostVo;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 *
 * CostOfGradeSubject 表数据服务层接口实现类
 *
 */
@Service
public class CostOfGradeSubjectServiceImpl extends SuperServiceImpl<CostOfGradeSubjectMapper, CostOfGradeSubject,Long> implements ICostOfGradeSubjectService {

    @Override
    public List<CostOfGradeSubject> findCostByGradeIdsAndSubjectIds(List<Long> gradeIds, List<Long> subjectIds, List<Long> mainAccountIds, Date startDate, Date endDate,String ...columns) {
        Example<CostOfGradeSubject> example=CostOfGradeSubject.createExample();
        Example.Criteria criteria=example.createCriteria();
        criteria.andIn("mainAccountId",mainAccountIds);
        criteria.andIn("gradeId",gradeIds);
        criteria.andIn("subjectId",subjectIds);
        criteria.andGreaterThanOrEqualTo("effectTime",startDate);
        criteria.andLessThanOrEqualTo("effectTime",endDate);
        if (columns!=null){
            example.selectProperties(columns);
        }
        return  this.findListByExample(example);
    }

    @Override
    public List<CostOfGradeSubject> findCostByGradeIdsAndSubjectIdsAndFeeCategoryIds(List<Long> gradeIds, List<Long> subjectIds, List<Long> mainAccountIds, Date startDate, Date endDate, List<Long> feeCategoryIds) {
        Example<CostOfGradeSubject> example=CostOfGradeSubject.createExample();
        Example.Criteria criteria=example.createCriteria();
        criteria.andIn("mainAccountId",mainAccountIds);
        if (Utils.checkListNotEmpty(gradeIds)){
            criteria.andIn("gradeId",gradeIds);
        }
        if (Utils.checkListNotEmpty(subjectIds)){
            criteria.andIn("subjectId",subjectIds);
        }
        criteria.andGreaterThanOrEqualTo("effectTime",startDate);
        criteria.andLessThanOrEqualTo("effectTime",endDate);
        criteria.andIn("feeCategoryId",feeCategoryIds);
        return  this.findListByExample(example);
    }

    @Override
    public List<GradeSubjectCostVo> findGradeSubjectCost(GradeSubjectCostQueryVo gradeSubjectCostQueryVo) {
        return autoMapper.findGradeSubjectCost(gradeSubjectCostQueryVo);
    }

    @Override
    public Page<CostOfGradeSubject> findGradeSubjectCostPage(GradeSubjectCostQueryVo gradeSubjectCostQueryVo,int pageNo,int pageSize) {
        Example<CostOfGradeSubject> example=CostOfGradeSubject.createExample();
        Example.Criteria criteria=example.createCriteria();
        CriteriaUtils.fillCondition(criteria,gradeSubjectCostQueryVo);
        return this.findPageByExample(example,pageNo,pageSize);
    }
}